package org.hp.service;

import org.hp.dao.Dao;
import org.hp.util.PageBean;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class RecordServiceImpl implements RecordService {
    Dao Dao = new Dao();
    @Override
    public List<Map> queryAll() {
        List<Map> list = Dao.select("select * from house h,logistics l,record r where h.hid = r.hid and r.loid = l.loid");
        return list;
    }

    @Override
    public int add(int hid, int loid, Date retime, String reremark) {
        int num = Dao.update("insert into record values(null,?,?,?,?)",
         hid,loid,retime,reremark);
        return num;
    }

    @Override
    public int delete(int reid) {
        int num = Dao.update("delete from record where reid = ?", reid);
        return num;
    }

    @Override
    public Map<String, Object> queryOne(int reid) {
        List<Map> list = Dao.select("select * from house h,logistics l,record r where h.hid = r.hid and r.loid = l.loid and reid = ?", reid);
        if(list != null && list.toString() != ""){
//            System.out.println("查询一个："+list.get(0));
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public int update(int hid, int loid, String reremark, int reid) {
        int num = Dao.update("update record set hid = ?,loid = ?,reremark = ? where reid = ?",
                hid,loid,reremark, reid);
        return num;
    }

    @Override
    public PageBean<Map> queryList(int page, int limit, String sql, String... obj) {
//        System.out.println("修缮表ServiceImpl的page值："+page);
        return Dao.pageList(page,limit,sql);
    }

    @Override
    public List<Map> queryHid() {
        List<Map> list = Dao.select("select * from house");
        return list;
    }

    @Override
    public List<Map> queryLoid() {
        List<Map> list = Dao.select("select * from logistics");
        return list;
    }

}